package com.accenture.adf.newcodington.module20.sample;

import java.sql.Connection;
import java.sql.PreparedStatement;

public class InsertDemo {
	

		public static void main(String[] args) {
			try{
				//Obtaining a connection
				Connection con = ConnectionToDBDemo.getConnection();
				if(con != null)
				{
				System.out.println("Connection successfully established!");
				}
				
				//Creating a PreparedStatement with a query "insert into Student values(?,?,?)" 
				PreparedStatement pStmt = con.prepareStatement("insert into Student values(?,?,?)");
				
				//Changing parameters to appropriate values
				pStmt.setString(1,"S009");
				pStmt.setString(2,"Thomas");
				pStmt.setString(3,"C001");
				
				//Setting autoCommit to false 
				con.setAutoCommit(false);
				
				//Executing this query using executeUpdate()
				int rows = pStmt.executeUpdate();
				
				//Committing
				con.commit();	
				
				//Printing how many rows got added
				System.out.println(rows + " row(s) added!");
				
				//Closing the connection
				con.close();
				
			}catch (Exception e){
				System.out.println(e.getMessage());
			}

		}
}

